package com.hank.biz.sms;


import org.camunda.bpm.engine.RuntimeService;
import org.camunda.bpm.engine.delegate.DelegateExecution;
import org.camunda.bpm.engine.delegate.JavaDelegate;
import org.camunda.bpm.model.bpmn.Query;
import org.camunda.bpm.model.bpmn.instance.ExtensionElements;
import org.camunda.bpm.model.bpmn.instance.camunda.CamundaProperties;
import org.camunda.bpm.model.bpmn.instance.camunda.CamundaProperty;
import org.camunda.bpm.model.xml.type.ModelElementType;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Collection;


/**
 * Created by I073349 on 3/6/2017.
 */
public class LogService implements JavaDelegate {
    private static final Logger logger = LoggerFactory.getLogger(LogService.class);

    public void execute(DelegateExecution delegateExecution) throws Exception {
        logger.info("Print service for " + delegateExecution.getCurrentActivityName());
        RuntimeService runtimeService = delegateExecution.getProcessEngineServices().getRuntimeService();
        ExtensionElements extensionElements = delegateExecution.getBpmnModelElementInstance().getExtensionElements();
        if( extensionElements == null) {
            return;
        }
        Query<CamundaProperties> camundaPropertiesQuery = extensionElements.getElementsQuery().filterByType(CamundaProperties.class);
        Collection<CamundaProperty> properties = camundaPropertiesQuery.singleResult().getCamundaProperties();
        for (CamundaProperty property : properties) {
            String name = property.getCamundaName();
            String value = property.getCamundaValue();
            logger.info("camunda:property " + name + " --> " + value);
        }
    }
}
